<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib  uri="/WEB-INF/tlds/authorizetag.tld" prefix="px"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>生成优惠券</title>
<link href="/admin/public/bootstrap.min.css" title="" rel="stylesheet" />
<link href="/admin/font-awesome/css/font-awesome.min.css" rel="stylesheet">
<link href="/admin/public/animate.css" rel="stylesheet">
<link rel="stylesheet" href="/admin/public/inspinia.css" />
<link rel="stylesheet" href="/admin/css/pop-up.css" />
<link rel="stylesheet" href="/admin/css/plugins/toastr/toastr.min.css" />
<link rel="stylesheet" type="text/css" href="${request.getContext }/admin/css/xcConfirm.css"/>
<link href="/admin/css/plugins/chosen/chosen.css" rel="stylesheet">
  <!-- 开关控件样式 -->
<link rel="stylesheet" href="${request.getContext }/admin/css/plugins/switchery/switchery.css" />
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
	<script src="/admin/public/html5shiv.min.js"></script>
	<script src="/admin/public/respond.min.js"></script>
<![endif]-->
<style type="text/css">
.img{
	height: 130px;
	width:180px;
}
</style>
</head>
<body>
	<div id="wrapper" class="container">
		<div class="wrapper wrapper-content">
			<div class="right_box">
				<div style="border: none; box-shadow: none;" class="right_one row">
					<div class="col-md-12 col-sm-12 col-xs-12" style="float: left;">
						<form class="form-horizontal" method="post" id="biao" enctype="multipart/form-data"
							novalidate="novalidate">
							<div class="form-group">
								<label class="col-lg-2 control-label" >批次名称:</label>
								<div class="col-lg-6">
									<input type="text" id="batchName" name="batchName" class="form-control"  />
								</div>
							</div>
							<div class="form-group">
								<label class="col-lg-2 control-label">优惠券类型:</label>
								<div class="col-lg-9" style="margin-top: 5px;">
						            <input type="radio" onclick="Discount();" checked="checked" name="couponType" value="0"/>&nbsp;折扣券&nbsp;&nbsp;&nbsp;&nbsp;
						            <input type="radio" onclick="Cash();" name="couponType" value="1"/>&nbsp;代金券&nbsp;&nbsp;&nbsp;&nbsp;
                                    <span class="field-validation-valid" data-valmsg-for="Title" data-valmsg-replace="true"></span>
                                </div>
							</div>
							<div class="form-group" id="SetupDiscount">
								<label class="col-lg-2 control-label" >设置折扣:</label>
								<div class="col-lg-6">
									<input type="text" id="discount" name="discount" class="form-control" onkeyup="value=value.replace(/[^\d.]/g,'')"/>
									<span class="text-danger field-validation-valid" data-valmsg-for="password" data-valmsg-replace="true">说明：直接输入数字 9.5 即  9.5折</span>
								</div>
							</div>
							<div class="form-group" id="SetupCash" style="display: none;">
								<label class="col-lg-2 control-label">设置价格:</label>
								<div class="col-lg-6">
									<input type="text" id="price" name="price" class="form-control" onkeyup="value=value.replace(/[^\d.]/g,'')"/>
								</div>
							</div>
							<div class="form-group">
								<label class="col-lg-2 control-label">有效期:</label>
								<div class="col-lg-6">
									<img style="position: relative;left:-250px; top: 6px" src="/admin/img/datePicker.gif"/>
			            			<input type="text" placeholder="开始时间" style="width:175px;float:left;" id="start" name="startTime" class= "form-control" onFocus="WdatePicker({lang:'zh-cn',dateFmt:'yyyy-MM-dd'})" />
			            			<span class="col-lg-1 col-md-1 col-sm-1" style="float: left; margin-top: 8px;">—</span>
			            			<img style="position: relative;left:-46px; top: 6px" src="/admin/img/datePicker.gif"/>
			            			<input type="text" placeholder="开始时间" style="width:175px;float:left;" id="end" name="endTime" class= "form-control" onFocus="WdatePicker({lang:'zh-cn',dateFmt:'yyyy-MM-dd'})" />
								</div>
							</div>
							<div class="form-group">
								<label class="col-lg-2 control-label">生成数量:</label>
								<div class="col-lg-6">
									<input type="text" id="number" name="number" class="form-control" onkeyup="value=value.replace(/[^\d.]/g,'')"/>
								</div>
							</div>
							<div class="form-group" style="height:60px;">
								<label class="col-lg-2 control-label">适用门店:</label>
								<div class="input-group">
									<div class="col-lg-6 sel1" >
									<select data-placeholder="--请选择--" class="chosen-select" multiple style="width:350px;" tabindex="4">
										<c:forEach items="${selshop }" var="item">
											<option value="${item.shopId }">${item.shopName }</option>
										</c:forEach>
									</select>
									</div>
								</div>
							</div>
							<div class="form-group" style="height:60px;">
								<label class="col-lg-2 control-label">适用课程:</label>
								<div class="input-group">
									<div class="col-lg-6 sel2" >
									<select data-placeholder="--请选择--" class="chosen-select2" multiple style="width:350px;" tabindex="4">
										<c:forEach items="${classType }" var="item">
											<option value="${item.kcType }">${item.typeName }</option>
										</c:forEach>
									</select>
									</div>
								</div>
							</div>
							<div class="form-group">
								<label class="col-lg-2 control-label">备注:</label>
								<div class="col-md-6">
									<textarea class="form-control" id="remark" name="remark" rows="" cols=""></textarea>
								</div>
							</div>
								<input type="hidden" id="checkTF" value="0">
								<input type="button" onclick="savePact();" id="btnn" style="width:82px;height:34px; display:none; margin-left: 12px"  value="保存"   class="col-lg-3 btn btn-success"/>
						</form>
					</div>
				</div>
			</div>
		</div>
	</div>
	<script src="/admin/public/jquery-1.11.3.js"></script>
	<script src="/admin/public/bootstrap.min.js" type="text/javascript"></script>
	<script src="${request.getContext }/admin/js/xcConfirm.js" type="text/javascript" charset="utf-8"></script>
	<script src="/admin/js/plugins/toastr/toastr.min.js"></script>
	<script src="/admin/js/new_page.js"></script>
	<script src="/admin/js/jquery.form.min.js"></script>
	<script src="${request.getContextPath }/admin/My97/WdatePicker.js"></script>
	<script src="/admin/js/plugins/chosen/chosen.jquery.js"></script>
</body>
<script type="text/javascript">
		function preview(file, i) {
			var prevDiv = document.getElementById('preview' + i);
			if (file.files && file.files[0]) {
				var reader = new FileReader();
				reader.onload = function(evt) {
					prevDiv.innerHTML = '<img class="img" src="' + evt.target.result + '" />';
				}
				reader.readAsDataURL(file.files[0]);
			} else {
				prevDiv.innerHTML = '<div class="img" style="filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale,src=\'' + file.value + '\'"></div>';
			}
		}
		var config = {
				'.chosen-select': {},
				'.chosen-select-deselect': {
					allow_single_deselect: true
				},
				'.chosen-select-no-single': {
					disable_search_threshold: 10
				},
				'.chosen-select-no-results': {
					no_results_text: 'Oops, nothing found!'
				},
				'.chosen-select-width': {
					width: "95%"
				}
			}
			for(var selector in config) {
				$(selector).chosen(config[selector]);
			}
		
		var config2 = {
				'.chosen-select2': {},
				'.chosen-select-deselect': {
					allow_single_deselect: true
				},
				'.chosen-select-no-single': {
					disable_search_threshold: 10
				},
				'.chosen-select-no-results': {
					no_results_text: 'Oops, nothing found!'
				},
				'.chosen-select-width': {
					width: "95%"
				}
			}
			for(var selector2 in config2) {
				$(selector2).chosen(config2[selector]);
			}
	</script>
<script>
 //添加优惠券信息
function savePact(){
	var len=$(".sel1 .chosen-container .chosen-choices .search-choice span").length;
	var shopID=""
	var shopID2=""
	for(var i=0;i<len;i++){
		shopID2=$(".sel1 .chosen-container .chosen-choices .search-choice span").eq(i).data("value");
		if(i==0){
			shopID=shopID2;
		}else{
			shopID += ("," +shopID2);
		}
	}
	var leng=$(".sel2 .chosen-container .chosen-choices .search-choice span").length;
	var kc=""
	var kc2=""
	for(var i=0;i<leng;i++){
		kc2=$(".sel2 .chosen-container .chosen-choices .search-choice span").eq(i).data("value");
		if(i==0){
			kc=kc2;
		}else{
			kc += ("," +kc2);
		}
	}
	var batchName=$("#batchName").val();
	if(batchName.length==0){
		alert("批次名称不能为空！");
		return false;
	}
	var couponType = $("input[name='couponType']:checked").val();
	if(0==couponType){
		var discount = $("#discount").val();
		if(discount.length==0){
			alert("请设置折扣值！！！");
			return false;
		}
	}
	if(1==couponType){
		var price = $("#price").val();
		if(price.length==0){
			alert("请设置价格！！！");
			return false;
		}
	}
	
	var start=$("#start").val();
	var end =$("#end").val();
	if(start.length==0 || end.length==0){
		alert("有效期不能为空！");
		return false;
	}
	var number=$("#number").val();
	if(number.length==0){
		alert("生成数量不能为空！");
		return false;
	}
	
	if(len==0){
	alert("适用门店不能为空！");
	return false;
	}
	if(leng==0){
	alert("适用课程不能为空！");
	return false;
	}
	
	var remark=$("#remark").val();
	if(remark.length==0){
		alert("备注不能为空！");
		return false;
	}
	$('#biao').ajaxSubmit({
        type:"post",
        data:{"shopId":shopID,"classType":kc},
        dataType:"json",
        url:"/admin/system/insert",
        success:function(data){
        	if (data.success) {
				alert(data.msg);
				$('#ifr',window.parent.document).attr('src','/admin/system/coupon');
			}else{
				alert(data.msg);
				$('#ifr',window.parent.document).attr('src','/admin/system/coupon');
			}
        },
        error:function(data){
        	alert("未知的错误发生了！");
        }
    });
} 
//折扣券
 function Discount(){
	$("#SetupCash").hide();
	$("#price").val("");
	$("#SetupDiscount").show();
 }
 function Cash(){
	$("#SetupDiscount").hide();
	$("#discount").val("");
	$("#SetupCash").show();
 }
</script>
</html>